<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html ng-app="app" id="ng-app">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<%@include file="/include/style.jsp"%>
<%@include file="/include/script.jsp"%>
<script type="text/javascript">
function UserCtrl($scope, $http) {
	$scope.formCondition = {};
	
	Pagination.initialize("/user/findPage", $scope, $http);
	
	$scope.deleteUser = function(user){
		Message.confirm("确认", "是否删除该用户", function(){
		   $http.post("/user/delete/" + user.username).success(function(response){
			  if (response.success) {
				  $scope.search();
			  } else {
				  Message.error("提示", response.message);
			  } 
		   });
		});
	};
	
	$scope.createUser = function() {
		window.location.href = "/user/add";
	};
	
	$scope.editUser = function(user) {
		window.location.href = "/user/edit/" + user.username;
	};

	$scope.init = function() {
		$scope.search();
	};
	
	$scope.init();
};

app.controller('UserCtrl', UserCtrl);
</script>
</head>
<body ng-controller="UserCtrl">
	<div class="toolbar">
		<div class="left-area">
			<form ng-submit="search()">
				<input type="text" id="username" ng-model="formCondition.username" placeholder="用户名模糊匹配" class="form-control search-box">
			</form>
		</div>
  		<div class="right-area">
  			<permission:valid permission="<%=Constants.USER_CUD%>">
				<button class="btn btn-success" ng-click="createUser()"><i class="fa fa-plus"></i> 新增 </button>
			</permission:valid>
  		</div>
	</div>
	
	<div ng-show="page.rows.length>0">
		<table class="data-table">
			<thead>
				<tr>
					<th width="5%">序号</th>
					<th width="15%" ng-click="sortBy('username')" class="sort">用户名&nbsp;<i ng-class="direction('username')">&nbsp;</i></th>
					<th width="15%">角色</th>
					<th width="20%">邮箱</th>
					<th width="15%" ng-click="sortBy('last_visit_time')" class="sort">上次登录时间&nbsp;<i ng-class="direction('last_visit_time')">&nbsp;</i></th>
					<th width="15%">操作</th>
				</tr> 
			</thead>
			<tbody class="ng-scope">
				<tr ng-repeat="user in page.rows">
					<td align="center">{{$index + 1}}</td>
					<td>{{user.username}}</td>
					<td align="center">{{user.roleName}}</td>
					<td>{{user.email}}</td>
					<td align="center">{{user.lastVisitTime | date: 'yyyy-MM-dd HH:mm:ss'}}</td>
					<td align="center">
						<permission:valid permission="<%=Constants.USER_CUD%>">
							<span class="btn btn-link" ng-click="editUser(user)" ng-show="user.reserved!=1"><i class="fa fa-pencil"></i> 修改</span>
							<span class="btn btn-link" ng-click="deleteUser(user)" ng-show="user.reserved!=1"><i class="fa fa-trash"></i> 删除</span>
						</permission:valid>
					</td>
				</tr>
			</tbody>
		</table>
		
		<%@include file="/include/pageBar.jsp"%>
	</div>
	
	<div class="alert alert-success" style="clear: both;" ng-show='page.rows.length==0'>
		暂无数据！
	</div>
</body>
</html>